﻿<?xml version="1.0" encoding="utf-8"?>
<Window
	x:Class="ICSharpCode.CodeQualityAnalysis.MainWindow"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls;assembly=ICSharpCode.WpfDesign.Designer"
	xmlns:GraphSharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
	xmlns:Graph="clr-namespace:ICSharpCode.CodeQualityAnalysis.Controls" 
	xmlns:src="clr-namespace:ICSharpCode.CodeQualityAnalysis"
	xmlns:debug="clr-namespace:System.Diagnostics;assembly=System"
	xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
	xmlns:tree="http://icsharpcode.net/sharpdevelop/treeview"
	xmlns:sys="clr-namespace:System;assembly=mscorlib"
	xmlns:t="clr-namespace:TreeMaps.Controls;assembly=TreeMaps"
	xmlns:loc ="clr-namespace:ICSharpCode.CodeQualityAnalysis.Utility.Localizeable"
	xmlns:util="clr-namespace:ICSharpCode.CodeQualityAnalysis.Utility"
	xmlns:core="http://icsharpcode.net/sharpdevelop/core"
	Title="{Binding FrmTitle}"
	x:Name="root">
	
	<Window.DataContext>
		<src:MainWindowViewModel />
	</Window.DataContext>
	
	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary
					Source="../Resources/GraphTemplate.xaml" />
				<ResourceDictionary
					Source="../Resources/GridSplitterTemplate.xaml" />
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</Window.Resources>
	
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition
				Height="Auto" />
			<RowDefinition />
			<RowDefinition
				Height="Auto" />
		</Grid.RowDefinitions>
		<Menu>
			<MenuItem Header="File">
				<MenuItem Header="{Binding btnOpenAssembly}"
				          Click="btnOpenAssembly_Click">
				</MenuItem>
				<MenuItem Header="{core:Localize Global.CloseButtonText}" Click="MenuClose_Click">
				</MenuItem>
			</MenuItem>
		
		</Menu>
		<TabControl
			Grid.Row="1"
			IsEnabled="{Binding MainTabEnable}"
			SelectedItem="{Binding SelectedTabItem}">
			<!-- It is enabled once assembly is loaded. -->
			<TabItem
				Header="{Binding TabDependencyGraph}">
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition
							Height="Auto" />
						<RowDefinition />
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition
							Width="250px" />
						<ColumnDefinition
							Width="Auto"></ColumnDefinition>
						<ColumnDefinition />
						<ColumnDefinition
							Width="Auto"></ColumnDefinition>
						<ColumnDefinition
							Width="200px" />
					</Grid.ColumnDefinitions>
					<ToolBarTray
						Grid.Row="0"
						Grid.ColumnSpan="5">
						<ToolBar>
							<Button
								Name="btnRelayout"
								Click="btnRelayout_Click"
								Margin="0 0 5 0">Relayout</Button>
							<Button
								Name="btnContinueLayout"
								Click="btnContinueLayout_Click"
								Margin="0 0 5 0">Continue Layout</Button>
							<Button
								Name="btnResetGraph"
								Click="btnResetGraph_Click"
								Margin="0 0 5 0">Reset Graph</Button>
							<Button
								Name="btnSaveImageGraph"
								Click="btnSaveImageGraph_Click">Save an Image of Graph</Button>
						</ToolBar>
					</ToolBarTray>
					<tree:SharpTreeView
						Name="definitionTree"
						Grid.Row="1"
						Grid.Column="0"
						Margin="2"
						SelectionChanged="definitionTree_SelectedItemChanged"></tree:SharpTreeView>
					<GridSplitter
						Grid.Column="1"
						Grid.Row="1"
						Grid.RowSpan="2"
						ResizeDirection="Columns"
						HorizontalAlignment="Stretch"
						VerticalAlignment="Stretch"
						Style="{DynamicResource GridSplitterStyle1}"></GridSplitter>
					<Controls:ZoomControl
						Grid.Row="1"
						Grid.Column="2"
						Name="zoom"
						AlwaysShowZoomButtons="True"
						HorizontalScrollBarVisibility="Visible"
						VerticalScrollBarVisibility="Visible">
						<Graph:DependencyGraphLayout
							x:Name="graphLayout"
							LayoutAlgorithmType="LinLog"
							OverlapRemovalAlgorithmType="FSA"
							HighlightAlgorithmType="Simple"
							VertexClick="graphLayout_VertexClick" />
					</Controls:ZoomControl>
					<GridSplitter
						Grid.Column="3"
						Grid.Row="2"
						ResizeDirection="Columns"
						ResizeBehavior="PreviousAndNext"
						Style="{DynamicResource GridSplitterStyle1}"></GridSplitter>
					<TextBlock
						Name="txbTypeInfo"
						Text="{Binding TypeInfo}"
						Margin="2"
						MinWidth="30"
						Grid.Column="4"
						Grid.Row="1"
						Padding="5"
						Background="LightBlue" />
				</Grid>
			</TabItem>
			
			<TabItem
				Header="{Binding TabDependencyMatrix}">
				<Graph:TreeMatrixControl
					x:Name="matrixControl"></Graph:TreeMatrixControl>
			</TabItem>
			
			<TabItem
				Name="TreeMapTabItem"
				Header="{Binding TabMetrics}"
				IsEnabled="{Binding MetrixTabEnable}">
				<TabItem.Resources>
					<ObjectDataProvider MethodName="GetValues"
						ObjectType="{x:Type sys:Enum}"
						x:Key="MetricsLevel">
						<ObjectDataProvider.MethodParameters>
							<x:Type TypeName="src:MetricsLevel" />
						</ObjectDataProvider.MethodParameters>
					</ObjectDataProvider>
					
					<loc:EnumToFriendlyNameConverter x:Key="enumItemsConverter"/>

					<DataTemplate
						x:Key="TreeMapDataTemplate">
						<Border
							Background="AliceBlue"
							BorderBrush="Black"
							BorderThickness="1">
							<StackPanel ToolTip="{Binding ToolTipString}">
								<TextBlock
									Text="{Binding DeclaringType.Name}" />
								<TextBlock
									Text="{Binding Name}"
									VerticalAlignment="Top"
									TextAlignment="Center"
									TextWrapping="Wrap" />
							</StackPanel>
						</Border>
					</DataTemplate>
				</TabItem.Resources>
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition
							Height="Auto" />
						<RowDefinition
							Height="*" />
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition
							Width="*" />
					</Grid.ColumnDefinitions>
					
					<ToolBarTray
						Background="White"
						Grid.Row="0"
						Grid.Column="0">
						<ToolBar>
							<TextBlock Text="Level: " />
							
							<util:ComboBoxWithCommand Width="200"
								ItemsSource="{Binding Source={StaticResource MetricsLevel}}"
								SelectedItem="{Binding SelectedMetricsLevel}"
								Command="{Binding ActivateMetrics}">
							</util:ComboBoxWithCommand>
							
							<TextBlock  Margin="4,0,0,0" Text="Metric: " />
							
							<util:ComboBoxWithCommand Width="200" Margin="4,0,0,0"
								ItemsSource="{Binding ItemsWithCommand}"
								SelectedItem="{Binding SelectedItemWithCommand}"
								Command="{Binding ExecuteSelectedItemWithCommand}">
								<util:ComboBoxWithCommand.ItemTemplate>
									<DataTemplate>
									<Label Content="{Binding Description}"></Label>
									</DataTemplate>
								</util:ComboBoxWithCommand.ItemTemplate>
							</util:ComboBoxWithCommand>
						</ToolBar>
					</ToolBarTray>
					
	<!--  http://treemaps.codeplex.com/-->
					
					<t:TreeMaps 
						Grid.Row="1" 
						Grid.Column="0"
						Loaded="TreeMaps_Loaded"
						ItemsSource="{Binding Nodes}"
						Background="LightGray"
						TreeMapMode="Squarified"
						ItemTemplate="{StaticResource TreeMapDataTemplate}"
						ValuePropertyName="{Binding TreeValueProperty}">
					</t:TreeMaps>
				</Grid>
			</TabItem>
		</TabControl>
		
		<StatusBar
			Grid.Row="2">
			<StatusBarItem
				HorizontalAlignment="Left"
				Visibility="{Binding ProgressbarVisible}">
				<StackPanel
					Orientation="Horizontal">
					<TextBlock
						Text="Loading " />
					<TextBlock
						Text="{Binding FileName}"></TextBlock>
					<TextBlock
						Text="..."
						Margin="0, 0, 5, 0" />
					<ProgressBar
						IsIndeterminate="True"
						Width="95"
						Height="15" />
				</StackPanel>
			</StatusBarItem>
			
			<StatusBarItem
				HorizontalAlignment="Right"
				Visibility="{Binding AssemblyStatsVisible}">
				<StatusBarItem>
						<StackPanel
							Orientation="Horizontal">
							<TextBlock
								Text="Summary: " />
							<TextBlock
								Text="{Binding Summary}" />
						</StackPanel>
					</StatusBarItem>
			</StatusBarItem>
		</StatusBar>
	
	</Grid>
</Window>